package com.fan.leetcode;

import org.junit.jupiter.api.Test;

/**
 * 11. 盛最多水的容器
 *
 * @author zhangFan
 * @since 2021/9/6 15:03
 */
public class Question11 {
    @Test
    void test() {
        System.out.println("maxArea() = " + maxArea(new int[]{1, 8, 6, 2, 5, 4, 8, 3, 7}));
    }

    public int maxArea(int[] height) {
        int max = 0;
        int i = 0, j = height.length - 1;
        while (i < j) {
            if (height[i] < height[j]) {
                max = Math.max((j - i) * height[i++], max);
            } else {
                max = Math.max((j - i) * height[j--], max);
            }
        }
        return max;
    }
}
